<?php
include 'AdminController.php';
class Admin_ConfigController extends Admin_AdminController
{
    public function init(){
    	//レイアウトを設定する
        $layoutPath = APPLICATION_PATH . '/templates/admin/admin';
        $option = array('layout' => 'index', 'layoutPath' => $layoutPath);
        Zend_Layout::startMvc($option);
        
        //アクティブメニューを設定
        $this->view->active_menu = "config";
    }
	
	public function feeAction ()
    {
    	//必要なクラスを読み込む
    	Zend_Loader::loadClass("ConfigModel");
    	
    	$request = $this->getRequest();
    	$view = $this->view;
    	$model = new ConfigModel();
    	$model->init();
    	
    	if($request->isPost()){
			$order_fee = $request->getParam("order_fee");
			$cancel_fee = $request->getParam("cancel_fee");
			$penalty_money = $request->getParam("penalty_money");
    		
			$model->set("ORDER_FEE", $order_fee);
			$model->set("CANCEL_FEE", $cancel_fee);
			$model->set("PENALTY_MONEY", $penalty_money);
			
			$model->update();
			
			//TODO set data to view
			$view->order_fee = $order_fee;
			$view->cancel_fee = $cancel_fee;
			$view->penalty_money = $penalty_money;
			
    		//TODO 通知表示
    		$view->message = "手数料が変更しました。";	
    	}else{
    		$view->order_fee = $model->get("ORDER_FEE");
    		$view->cancel_fee = $model->get("CANCEL_FEE");
    		$view->penalty_money = $model->get("PENALTY_MONEY");
    	}
    	
    	//TODO Navigator を設定
    	$nav['ホーム'] = "/admin";
    	$nav['システム定数'] = "/admin/config/fee";
    	$view->nav = $nav;
    }
    
	public function paymentAccountAction ()
    {
    	//必要なクラスを読み込む
    	Zend_Loader::loadClass("ConfigModel");
    	
    	$request = $this->getRequest();
    	$view = $this->view;
    	$model = new ConfigModel();
    	$model->init();
    	
    	if($request->isPost()){
			$payment_system_id = $request->getParam("payment_system_id");
			$payment_user_id = $request->getParam("payment_user_id");
			$payment_user_name = $request->getParam("payment_user_name");
    		
			$model->set("PAYMENT_SYSTEM_ID", $payment_system_id);
			$model->set("PAYMENT_USER_ID", $payment_user_id);
			$model->set("PAYMENT_USER_NAME", $payment_user_name);
			
			$model->update();
			
			//TODO set data to view
			$view->payment_system_id = $payment_system_id;
			$view->payment_user_id = $payment_user_id;
			$view->payment_user_name = $payment_user_name;
			
    		//TODO 通知表示
    		$view->message = "請求システム情報が変更されました。";	
    	}else{
    		$view->payment_system_id = $model->get("PAYMENT_SYSTEM_ID");
    		$view->payment_user_id = $model->get("PAYMENT_USER_ID");
    		$view->payment_user_name = $model->get("PAYMENT_USER_NAME");
    	}
    	
    	//TODO Navigator を設定
    	$nav['ホーム'] = "/admin";
    	$nav['システム定数'] = "/admin/config/payment_account";
    	$view->nav = $nav;
    }
    
	public function mailAction ()
    {
    	//必要なクラスを読み込む
    	Zend_Loader::loadClass("ConfigModel");
    	
    	$request = $this->getRequest();
    	$view = $this->view;
    	$model = new ConfigModel();
    	$model->init();
    	
    	if($request->isPost()){
			$mail_host = $request->getParam("mail_host");
			$mail_port = $request->getParam("mail_port");
			$mail_protocol = $request->getParam("mail_protocol");
			$mail_username = $request->getParam("mail_username");
			$mail_password = $request->getParam("mail_password");
    		
			$model->set("MAIL_HOST", $mail_host);
			$model->set("MAIL_PORT", $mail_port);
			$model->set("MAIL_PROTOCOL", $mail_protocol);
			$model->set("MAIL_USERNAME", $mail_username);
			$model->set("MAIL_PASSWORD", $mail_password);
			
			$model->update();
			
			//TODO set data to view
			$view->mail_host = $mail_host;
			$view->mail_port = $mail_port;
			$view->mail_protocol = $mail_protocol;
			$view->mail_username = $mail_username;
			$view->mail_password = $mail_password;
			
    		//TODO 通知表示
    		$view->message = "メール設定が変更されました。";	
    	}else{
    		$view->mail_host = $model->get("MAIL_HOST");
			$view->mail_port = $model->get("MAIL_PORT");
			$view->mail_protocol = $model->get("MAIL_PROTOCOL");
			$view->mail_username = $model->get("MAIL_USERNAME");
			$view->mail_password = $model->get("MAIL_PASSWORD");
    	}
    	
    	//TODO Navigator を設定
    	$nav['ホーム'] = "/admin";
    	$nav['システム定数'] = "/admin/config/mail";
    	$view->nav = $nav;
    }
}